package com.kudian.restful.service;

import com.kudian.common.persistence.HibernateDao;
import com.kudian.common.service.BaseService;
import com.kudian.restful.dao.AdDao;
import com.kudian.restful.dao.AppVersionDao;
import com.kudian.restful.dao.LayoutDao;
import com.kudian.restful.entity.Ad;
import com.kudian.restful.entity.AppVersion;
import com.kudian.restful.entity.Cart;
import com.kudian.restful.vo.appversion.AppVersionRetVO;
import com.kudian.restful.vo.appversion.AppVersionVO;
import org.apache.log4j.Logger;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by Administrator on 2016/4/18.
 */
@Service
@Transactional(readOnly = true)
public class AppVersionService extends BaseService<AppVersion, Integer> {
    private static final Logger logger = Logger.getLogger(AppVersionService.class);

    @Autowired
    private AppVersionDao appVersionDao;

    @Override
    public HibernateDao<AppVersion, Integer> getEntityDao() {
        return appVersionDao;
    }

    public AppVersionRetVO getCurrentVersion(AppVersionVO vo) {

        List<AppVersion> avs = appVersionDao.findbyorder("addTime", false,
                Restrictions.eq("phoneSys", vo.getPhoneSys()),
                Restrictions.eq("appType", vo.getAppType()));
        AppVersionRetVO retvo = new AppVersionRetVO();
        retvo.setPhoneSys(vo.getPhoneSys());
        if (avs == null || avs.isEmpty()) {
            retvo.setCurVer("");
            return retvo;
        }
        AppVersion av = avs.get(0);
        retvo.setCurVer(av.getCurVer());
        return retvo;
    }
}
